HTMLify
Implement Lower Bound.cpp
Views: 1 | Author: cody
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | int lowerBound(vector<int> arr, int n, int x) { int start = 0; int end = n-1; int mid = start +(end - start) /2; int ans = n; while(start<=end){ if(arr[mid]>= x){ ans = mid; end = mid - 1; } else{ start = mid + 1; } mid = start + (end - start) /2; } return ans; } |